package com.train.daily.facade.admin;

import cn.hutool.core.bean.BeanUtil;
import com.train.common.group.AddGroup;
import com.train.common.group.EditGroup;
import com.train.common.group.QueryGroup;
import com.train.common.resp.CommonResp;
import com.train.common.resp.PageResp;
import com.train.daily.dto.carriage.DailyTrainCarriageAddOrEditDTO;
import com.train.daily.dto.carriage.DailyTrainCarriagePageDTO;
import com.train.daily.req.carriage.DailyTrainCarriageAddOrEditReq;
import com.train.daily.req.carriage.DailyTrainCarriagePageReq;
import com.train.daily.resp.carriage.DailyTrainCarriagePageResp;
import com.train.daily.service.DailyTrainCarriageService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * dailyTrainCarriage Facade 实现类
 * @author baitiaojun
 * @createDate 2025-03-01 21:20:49
 */
@RestController("adminDailyTrainCarriageFacade")
@RequiredArgsConstructor
@RequestMapping("/admin/train-carriage")
public class DailyTrainCarriageFacade {

    private final DailyTrainCarriageService dailyTrainCarriageService;

    @PostMapping("page")
    public CommonResp pageList(@RequestBody @Validated(QueryGroup.class) DailyTrainCarriagePageReq req) {
        DailyTrainCarriagePageDTO dailyTrainCarriagePageDTO = BeanUtil.copyProperties(req, DailyTrainCarriagePageDTO.class);
        PageResp<DailyTrainCarriagePageResp> pageResp = dailyTrainCarriageService.pageList(dailyTrainCarriagePageDTO);
        return CommonResp.ok(pageResp);
    }

    @PostMapping("add")
    public CommonResp add(@RequestBody @Validated(AddGroup.class) DailyTrainCarriageAddOrEditReq req) {
        DailyTrainCarriageAddOrEditDTO dailyTrainCarriageAddOrEditDTO = BeanUtil.copyProperties(req, DailyTrainCarriageAddOrEditDTO.class);
        dailyTrainCarriageService.addOrEditDailyTrainCarriage(dailyTrainCarriageAddOrEditDTO);
        return CommonResp.ok();
    }

    @PostMapping("edit")
    public CommonResp edit(@RequestBody @Validated(EditGroup.class) DailyTrainCarriageAddOrEditReq req) {
        DailyTrainCarriageAddOrEditDTO dailyTrainCarriageAddOrEditDTO = BeanUtil.copyProperties(req, DailyTrainCarriageAddOrEditDTO.class);
        dailyTrainCarriageService.addOrEditDailyTrainCarriage(dailyTrainCarriageAddOrEditDTO);
        return CommonResp.ok();
    }

    @DeleteMapping("remove/{id}")
    public CommonResp delete(@PathVariable("id") Long id) {
        dailyTrainCarriageService.remove(id);
        return CommonResp.ok();
    }
}
